using System.Linq;
using Magiq.Behaviors;
using Magiq.Query;

namespace Magiq.Databases.Query
{
    public class DatabaseQueryBehavior<T> : DefaultBehavior, IDatabaseQueryBehavior<T> where T : class
    {
        private IDatabaseAdapter databaseAdapter;
        private IQuery<T> query;

        public void Initialize(IDatabaseAdapter databaseAdapter, IQuery<T> query)
        {
            this.databaseAdapter = databaseAdapter;
            this.query = query;
        }

        public DatabaseQuery<T> BuildDatabaseQuery()
        {
            return databaseAdapter.BuildDatabaseQuery(query);
        }

        public IQueryable<T> GetQueryableFrom(DatabaseQuery<T> databaseQuery)
        {
            return databaseAdapter.GetQueryable(databaseQuery);
        }
    }
}